home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_cspace.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  6.8 KB  |  229 lines

  1. %    Copyright (C) 2002 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_cspace.ps 8962 2008-08-11 14:16:18Z ken $
  14. % basic colorspace mechanism
  15.  
  16. %
  17. % There have been some major changes to the PostScript colour handling.
  18. % In particular, the vast majority of the colour space code has been
  19. % converted from PostScript to C. This file has been extensively
  20. % modified, as has gs_icc.ps. The remaining PostScript files which 
  21. % previously implemented colour space handling; gs_ciecs2.ps, gs_ciecs3.ps
  22. % gs_devcs.ps, gs_devn.ps, gs_devpxl.ps, gs_indxd.ps, gs_patrn.ps and
  23. % gs_sepr.ps have been superceded by the C code and removed.
  24. %
  25. % gs_lev2.ps and gs_ll3.ps have also been modified so that they no longer
  26. % attempt to execute these PostScript files.
  27. %
  28. .currentglobal true .setglobal
  29. systemdict begin
  30.  
  31. %
  32. % gs_res.ps, and possibly other files, use this dictionary. Formerly
  33. % in cspace_util, moved to systemdict.
  34. %
  35. 20 dict dup /colorspacedict exch def
  36.  
  37. begin % colorspacedict
  38.  
  39. %
  40. % gs_res.ps uses these entries in colorspacedict
  41. % to populate the ColorSpaceFamily resource, so we need
  42. % to add the supported spaces.
  43. %
  44. /DeviceGray [] def
  45. /DeviceRGB [] def
  46. /DeviceCMYK [] def
  47. end % colorspacedict
  48.  
  49. %
  50. % Global, read-only, unpacked, array-form device color spaces
  51. % We need to return an array argument in response to currentcolorspace
  52. % even if the argument presented to setcolorspace was a simple device
  53. % space name. Not only that, but in order to satisfy some Adobe
  54. % applications, it must be the *same* array every time. The only way
  55. % to do that is to define an appropriate set initial arrays and always return 
  56. % one of those. These arrays are defined here.
  57. %
  58. /DeviceGray_array /DeviceGray 1 array astore readonly def
  59. /DeviceRGB_array  /DeviceRGB  1 array astore readonly def
  60. /DeviceCMYK_array /DeviceCMYK 1 array astore readonly def
  61.  
  62. %
  63. %   -   initgraphics   -
  64. %
  65. % The internal routine gs_initgraphics doesn't (re)set the color space,
  66. % so we must redefine the operation to do it here.
  67. %
  68. %
  69. /initgraphics
  70.   { initgraphics systemdict /DeviceGray_array get setcolorspace }
  71. .bind odef 
  72.  
  73.  
  74. %
  75. % These routines used for the NOSUBSTDEVICECOLORS switch. This prevents 
  76. % substitution of DeviceGray, DeviceRGB and DeviceCMYK with a Default*
  77. % colour space when /UseCIEColors is true. If the job includes a
  78. % definition of /DefaltGray, DefaultRGB or DefaultCMYK then it also executes
  79. % .includecolorspace to allow the device to record the substitute space.
  80. %
  81. /..page_default_spaces 3 dict def
  82.  
  83. %
  84. % Used internally to retrieve any relevant default colour space.
  85. %
  86. % <Default space name> ..nosubstdevicetest false
  87. %                                          <Default space name> [space] true
  88. %
  89. % If the boolean is true then the C code must set the additional colour space
  90. % and execute .includecolorspace before finally setting a DeviceGray space.
  91. %
  92. /..nosubstdevicetest
  93. {
  94.   false mark 3 -1 roll
  95.   % If we have already recorded this space, don't repeat it.
  96.   systemdict /..page_default_spaces get 1 index known {
  97.     cleartomark
  98.   } {
  99.     {
  100.       % Check to see if this space was defined by defineresource, if so then 
  101.       % the job defined it, otherwise its the usual default, so ignore it. 
  102.       dup /ColorSpace resourcestatus {
  103.         pop 0 eq {
  104.           % Default* defined by defineresource
  105.           systemdict /..page_default_spaces get 1 index //true put
  106.           dup /ColorSpace findresource 4 2 roll pop pop true 
  107.         }{
  108.           cleartomark
  109.         } ifelse
  110.       }{
  111.         cleartomark
  112.       } ifelse
  113.     } stopped
  114.     {cleartomark}if
  115.   } ifelse
  116. }bind def
  117.  
  118. %
  119. % <color_space_name> ..includecolorspace -
  120. %
  121. /..includecolorspace
  122.   % If we have already recorded this space, don't repeat it.
  123.   systemdict /..page_default_spaces get 1 index known {
  124.     pop
  125.   } {
  126.     mark exch
  127.     {
  128.     % Check to see if this space was defined by defineresource, if so then 
  129.     % the job defined it, otherwise its the usual default, so ignore it. 
  130.     dup /ColorSpace resourcestatus {
  131.         pop 0 eq {
  132.           % Job defined /Default*, so record it and allow the device access to it
  133.           systemdict /..page_default_spaces get 1 index //true put
  134.           gsave
  135.           { dup /ColorSpace findresource //setcolorspace exec .includecolorspace
  136.           } stopped pop
  137.           grestore
  138.         } if
  139.       } if
  140.     } stopped pop
  141.     cleartomark
  142.   } ifelse
  143. } bind def
  144.  
  145. %
  146. % <color_space> <color_space_name> cs_substitute_generic <color_space1> <color_space2>
  147. %
  148. /cs_substitute_generic
  149. { .getuseciecolor
  150.     {NOSUBSTDEVICECOLORS 
  151.         { //..includecolorspace exec dup }
  152.         { /ColorSpace findresource }
  153.       ifelse
  154.     }
  155.     { pop dup }
  156.   ifelse
  157. }
  158. bind def
  159.  
  160. %
  161. % <color_space> <color_space_name> cs_substitute_DeviceRGB_for_PDFX_or_PDFA <color_space1> <color_space2>
  162. %
  163. /cs_substitute_DeviceRGB_for_PDFX_or_PDFA
  164. { systemdict /PDFX .knownget not { false } if
  165.   systemdict /PDFA .knownget not { false } if
  166.   or {
  167.     dup /ColorSpace resourcestatus {
  168.       pop pop
  169.     } {
  170.       (Error: Need a /DefaultRGB /ColorSpace resource for generating a PDF/X or PDF/A document.) =
  171.       /cs_substitute_DeviceRGB_for_PDFX_or_PDFA cvx /undefined signalerror
  172.     } ifelse
  173.     /ColorSpace findresource
  174.   } {
  175.     //cs_substitute_generic exec
  176.   } ifelse   
  177. } bind def
  178. end 
  179.  
  180. %
  181. % used to convert the DataSource of an ICCBased colour space into a 
  182. % file, if it isn't one already. This is required because the current
  183. % implementation of ICC spaces requires the data source to be a file.
  184. % This routine is *only* called from the PostScript interpreter when
  185. % setting an ICCBased space with a string data source.
  186. %
  187. /.convertICCSource 
  188. {
  189.   % make DataSource a file
  190.   dup 1 get /DataSource get type /stringtype eq
  191.   {
  192.     % build all new structures in local VM
  193.     .currentglobal exch //false .setglobal
  194.  
  195.     % check if we need to copy the color space and dictionary
  196.     2 copy eq
  197.     {
  198.       dup length array copy
  199.       dup 1 2 copy get dup length dict copy put
  200.     }
  201.     if
  202.  
  203.     % fetch DataSource, setting up stack for multiple puts
  204.     dup 1 2 copy get dup /DataSource 2 copy get
  205.  
  206.     % convert the string into a file
  207.     /ReusableStreamDecode filter
  208.  
  209.     % put the file into the dictioary, the dictionary into the array
  210.     put put
  211.  
  212.     % restore the VM mode
  213.     exch .setglobal
  214.   }
  215.   if
  216. } bind def
  217.  
  218. %
  219. % Set the initial device space
  220. %
  221. systemdict /DeviceGray_array get setcolorspace
  222.  
  223.  
  224. .setglobal
  225.